package io.renren.service.impl;

import io.config.dbconnect.InterBaseConnect;
import io.renren.dao.SysUserDao;
import io.renren.entity.SysUserEntity;
import io.renren.service.PaperService;
import io.renren.service.SysUserRoleService;
import io.renren.service.SysUserService;
import io.renren.utils.util.DatabaseUtil;
import io.renren.utils.util.exception.XMTException;

import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.shiro.crypto.hash.Sha256Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import interbase.interclient.PreparedStatement;
import interbase.interclient.ResultSet;



/**
 * 系统用户
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2016年9月18日 上午9:46:09
 */
@Service("paperService")
public class PaperServiceImpl implements PaperService {

	@Override
	public List<String> queryAllAreas() {
		// TODO Auto-generated method stub
		Connection conn = InterBaseConnect.getConn();
		String sql = "select * from areas";
        PreparedStatement pstmt;
        List<String> result = new ArrayList<String>();
        try {
            pstmt = (PreparedStatement)conn.prepareStatement(sql);
            ResultSet rs = (ResultSet) pstmt.executeQuery();
            int col = rs.getMetaData().getColumnCount();
            System.out.println("============================");
            while (rs.next()) {
            	result.add(new String(rs.getString("AREAID").getBytes("ISO8859_1"),"GBK"));
//                for (int i = 1; i <= col; i++) {
//                    try {
//                    	result+=new String(rs.getString(i).getBytes("ISO8859_1"),"GBK") + "\t";
//						System.out.print(new String(rs.getString(i).getBytes("ISO8859_1"),"GBK") + "\t");
//					} catch (UnsupportedEncodingException e) {
//						// TODO Auto-generated catch block
//						e.printStackTrace();
//					}
//                    if ((i == 2) && (rs.getString(i).length() < 8)) {
//                        System.out.print("\t");
//                    }
//                 }
                System.out.println("result" + result.toString());
            }
                System.out.println("============================");
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public List<String> queryJDBC() {
		// TODO Auto-generated method stub
		Connection con = null;
		String sql = "select * from areas";
        PreparedStatement pstmt;
        List<String> result = new ArrayList<String>();
		try {
			con = DatabaseUtil.getConnection("paper");
			pstmt = (PreparedStatement)con.prepareStatement(sql);
            ResultSet rs = (ResultSet) pstmt.executeQuery();
            while (rs.next()) {
            	result.add(new String(rs.getString("AREAID").getBytes("ISO8859_1"),"GBK"));
            	System.out.println("result" + result.toString());
            }
		} catch (XMTException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
            try {
                if (con != null) {
                    con.close();
                    con = null;
                }
            } catch (Exception exception) {
            	exception.printStackTrace();
            }
        }
		return result;
	}
	

	
}
